package com.lch.thread.blocking;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author: liuchenhui
 * @create: 2019-05-25 18:10
 **/
public class BlockingDemo {

    static ArrayBlockingQueue<String> ab = new ArrayBlockingQueue<String>(400);

    private void init() {
        new Thread(() -> {
            try {
                while (true) {
                    final String s = ab.take();
                    System.out.println("reveice---->" + s);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
    }

    public void addData(String data) throws InterruptedException {
        ab.add(data);
        System.out.println("addData---->" + data);
//        Thread.sleep(1000L);

    }

    public static void main(String[] args) throws InterruptedException {
        BlockingDemo blockingDemo = new BlockingDemo();
        for (int i = 0; i < 400; i++) {
            blockingDemo.addData("i" + i);
        }
        Thread.sleep(1000L);
        blockingDemo.init();
    }
}
